//继承模板
{extend name="public/base"}


//CSS
{block name="style"}
<link rel="stylesheet" href="__ADMIN_STATIC__/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
{/block}


{block name="breadcrumb" title="当前位置"}

{/block}
//正文区域
{block name="body"}{//---------------------------------------------------------------------------}
<div class="page-container">
	<form action="{:url('save')}" method="post" class="form form-horizontal" id="form1">
		<div id="tab-category" class="HuiTab">
			<div class="tabBar cl">
{volist name="group" id="item"}
                <span {if condition="$group_id eq $key"}class="current"{/if}>
                    <a href="{:url('index?group='.$key)}">{$item}</a>
                </span>
{/volist}

			</div>
			<div class="tabCon" style="display:block;">
			
{volist name="list" id="vo"}
				<div class="row cl" >
					<label class="form-label col-xs-3 col-sm-3">

					 <span title="{$vo.name}"> ( {$vo.name} ) {$vo.title} :<span> 
					 </label>
					<div class="formControls col-xs-8 col-sm-4">
	{switch name="vo.type"}
		{case value="bool"}
			<?php  $arr = preg_split('/[,;\r\n]+/', trim( $vo['extra'] , ",;\r\n"));?>
			<?php foreach($arr as $k => $v): ?>
				{php} $v = explode(':',$v);$checked = ($vo['value'] == $v[0]) ? 'checked':'' ;{/php}

						<div class="radio-box" style=" display:inline-block; min-width:100px;">
							<label><input type="radio" name="config[{$vo.name}]" value="{$v[0]}" {$checked} > {$v[1]} </label>
						</div>
			<?php endforeach; ?>
		{/case}
		{case value="select"}
						<span class="select-box">
							<select class="select" size="1" name="config[{$vo.name}}">

			<?php  $arr = preg_split('/[,;\r\n]+/', trim( $vo['extra'] , ",;\r\n"));?>
			<?php foreach($arr as $k => $v): ?>
				{php} $v = explode(':',$v);$selected = ($vo['value'] == $v[0]) ? 'selected':'' ;{/php}
						<option value="{$v[0]}" {$selected} > {$v[1]} </option>
			<?php endforeach; ?>

							</select>
						</span>
		{/case}
		{case value="text"}
						<input type="text" class="input-text" placeholder="" name="config[{$vo.name}]" value="{$vo.value}" />
		{/case}
		{case value="num"}
						<input type="text" class="input-text" placeholder="" name="config[{$vo.name}]" value="{$vo.value}"  style="width:100px;" />
		{/case}
		{case value="textarea"}
						<textarea name="config[{$vo.name}]" cols="" rows="" class="textarea"  placeholder="说点什么...">{$vo.value}</textarea>
		{/case}
		{default /}				
	{/switch}

					</div>
					<div class="col-xs-8 col-sm-5">

						<span class="dropDown dropDown_hover dropDown_css_A">
							<a class="dropDown_A" href="javascript:void(0)">
								<i class="icon Hui-iconfont">&#xe60c;</i>
							</a>
							<ul class="dropDown-menu menu ">
								<li class="upt"><a href="javascript:void(0);" onClick="pop_edit( {$vo.id}  )" ><i class="icon Hui-iconfont">&#xe60c;</i> 修改</a></li>
								<li class="del"><a href="javascript:void(0);" onClick="pop_del( {$vo.id} , '{$vo.title}' )" ><i class="icon Hui-iconfont">&#xe6e2;</i> 删除</a></li>
								<!-- <li class=""><a href="javascript:void(0);"> 其他</a></li> -->
							</ul>
						</span>

						{$vo.remark}
					</div>
				</div>
{/volist}


			</div>
			<div class="tabCon">
				1
			</div>
			<div class="tabCon">
				2
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">

				<input class="btn btn-success radius" type="button" onclick="pop_add()" value="&nbsp;&nbsp;添加配置项&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
{/block}
//-----------------------------------------------------------------------------------------------


<!--请在下方写此页面业务相关的脚本-->
//-----------------------------------------------------------------------------------------------
{block name="script"}
<script type="text/javascript" src="__ADMIN_STATIC__/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script> 
<script type="text/javascript">


/**
 * 添加
 * @return {[type]} [description]
 */

/**
 * 修改
 * @return {[type]} [description]
 */
function pop_add( id = 0 ){
	var url = "{:url("edit")}";
	return layer_show_full('添加配置', url );
}

function pop_edit( id = 0 ){
	var url = "{:url("edit")}"+ '?id=' + id;
	return layer_show_full('修改配置', url );
}









/**
 * 删除
 * @return {[type]} [description]
 */
function pop_del( id = 0 , title = ''){

    var url_del = '{:url('del')}';

    // var node = zTree.getSelectedNodes();
    //     if(!node || !node.length ){
    //         jBox.tip('请选择要删除的部门~~~');return;
    //     }
    //     node = node[0] ;

    var doDel = function(){
        jBox.tip('处理中...' , 'loading');  

        $.ajax({
            type:'post',
            url:url_del,
            data: {id : id },
            dataType:'json',
            success:function(d){
            	if(d.code == 1 ){
            		top.jBox.tip( d.msg , 'success' );
            		setTimeout(function(){
						// window.location.href=location.href
						location.reload();
            		},1000);
            	}else{
            		top.jBox.tip( d.msg , 'error' );
            	}
            },
            error:function(a,b,c){
                jBox.tip('ajax error：' + b );
            }
        });
    }
    

    var submit = function (v, h, f) {
        if (v == 'ok'){
            doDel(id);
        }else if (v == 'cancel'){
            // jBox.tip('取消...', 'info');
        }
        return true; //close
    };

    $.jBox.confirm("确定 "+title+" 删除吗？", "提示", submit);
}//end function pop_del()









$(function(){
	//
	// $("#tab-category").Huitab({
	// 	index:0
	// });

	//返回顶部
	$.Huitotop();

	//表单验证 提交
	$('#form1').validate({
		onkeyup:false, //在 keyup 时验证。
        onclick:true, // 在点击复选框和单选按钮时验证。
        onfocusout:false, //失去焦点时验证（不包括复选框/单选按钮）。
        onsubmit:true ,   // 提交时验证。设置为 false 就用其他方法去验证。
		focusCleanup:true,focusInvalid:false,
		//success:"valid", //验证成功 添加样式
		rules: {

      	},
		submitHandler:function(form){
            jBox.tip('loading...' , 'loading') ; 

            var $form  = $("form");
            var url = $form.attr('action');
            var type = $form.attr('method') || 'get';
            var data = $form.serialize();
            $.ajax({
            	url: url ,
            	type:type , // get post
            	data: data , 
            	dataType : 'html' ,
            	success:function(d){
            		try{d = JSON.parse(d);}catch(err){jBox.alert( d , '查看ajax返回值');return false;}
				    if( 0 == d.ret){
				    	jBox.tip( d.msg , 'success');
				    	setTimeout(function(){window.location.reload();},1000);
				    }else{
				    	jBox.tip( d.msg , 'error');
				    }
            	},
            	error:function(XMLHttpRequest, textStatus, errorThrown){
            		console.log( 'ajaxError : ' + textStatus );
            	},
            	complete:function(){
            		setTimeout(function(){jBox.closeTip();},3000);
            	}
            });
			// parent.$('.btn-refresh').click();
			// var index = parent.layer.getFrameIndex(window.name);
			// parent.layer.close(index);
		},
		showErrors:function(errorMap,errorList) {
			this.defaultShowErrors(); //默认验证 
			if( this.numberOfInvalids() ){
				jBox.tip( '有' + this.numberOfInvalids() + '个错误，请检查！' ,'error');
			}
    	}
	});
});//$(function(){


</script>

<style>
	

	
</style>



{/block}{//---------------------------------------------------------------------------}